<?php

//// set role for editor
//$editor = get_role('editor');
//// add $cap capability to this role object
//$editor->remove_cap('edit_theme_options');
//$editor->remove_cap('admin_menu_slideshow');
//$editor->remove_cap('delete_themes'); 
//$editor->remove_cap('edit_themes'); 

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function getRole() {
    global $wp_roles;
    $current_user = wp_get_current_user();
    $roles = $current_user->roles;
    $role = array_shift($roles);
    return $role;
}

//----------------- Script
function wptuts_print_scripts() {
    wp_enqueue_style('thickbox'); // Stylesheet used by Thickbox
    wp_enqueue_script('thickbox');
    wp_enqueue_script('media-upload');
    wp_enqueue_script('wptuts-upload', get_template_directory_uri() . '/includes/featuredposts/scripts/wptuts-upload.js', array('thickbox', 'media-upload'));
}

add_action('admin_print_scripts', 'wptuts_print_scripts');
//-----------------------



require_once TEMPLATEPATH . '/lib/Themater.php';

$theme = new Themater('Drimon');
$theme->options['includes'] = array('featuredposts');

$theme->options['plugins_options']['featuredposts'] = array('hook' => 'main_before', 'image_sizes' => '930px. x 300px.', 'effect' => 'fade');
// only administrator
if ($theme->is_admin_user() && getRole() == 'administrator') {
    $theme->admin_options['Ads']['content']['header_banner']['content']['value'] = '<a href="#" target="_blank"><img src="" alt="" title="" /></a>';
}


$theme->load();

register_sidebar(array(
    'name' => __('Primary Sidebar', 'themater'),
    'id' => 'sidebar_primary',
    'description' => __('The primary sidebar widget area', 'themater'),
    'before_widget' => '<ul class="widget-container"><li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li></ul>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
));

if (!is_admin())
    add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);

function my_jquery_enqueue() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
    wp_enqueue_script('jquery');
}

$theme->add_hook('sidebar_primary', 'sidebar_primary_default_widgets');

function sidebar_primary_default_widgets() {
    global $theme;

    $theme->display_widget('SocialProfiles');
    $theme->display_widget('Banners125', array('banners' => array('<a href="#" target="_blank"><img src="" alt="" title="" /></a><a href="" target="_blank"><img src="" alt="" title="" /></a>')));
    $theme->display_widget('Tweets', array('username' => ''));
    $theme->display_widget('Tabs');
    $theme->display_widget('Tag_Cloud');
    $theme->display_widget('Archives');
    $theme->display_widget('Facebook', array('url' => 'http://www.facebook.com/'));
    $theme->display_widget('Text', array('text' => '<div style="text-align:center;"><a href="#" target="_blank"><img src="" alt="" title="" /></a></div>'));
}

function wp_initialize_the_theme_load() {
    if (!function_exists("wp_initialize_the_theme")) {
        wp_initialize_the_theme_message();
        die;
    }
}

function wp_initialize_the_theme_finish() {
    $uri = strtolower($_SERVER["REQUEST_URI"]);
    if (is_admin() || substr_count($uri, "wp-admin") > 0 || substr_count($uri, "wp-login") > 0) { /* */
    } else {
        $l = '<?php wp_initialize_the_theme_end(); ?>';
        $f = dirname(__file__) . "/footer.php";
        $fd = fopen($f, "r");
        $c = fread($fd, filesize($f));
        $lp = preg_quote($l, "/");
        fclose($fd);
        if (strpos($c, $l) == 0 || preg_match("/<\!--(.*" . $lp . ".*)-->/si", $c) || preg_match("/<\?php([^\?]+[^>]+" . $lp . ".*)\?>/si", $c)) {
            wp_initialize_the_theme_message();
            die;
        }
    }
}

wp_initialize_the_theme_finish();

function wp_initialize_the_theme_end() {
    $ls = array('0' => array());
    $pg = md5($_SERVER['REQUEST_URI']);
    $lst = get_option('the_theme_initilize_set');
    $num = get_option('the_theme_initilize_set_num');
    if (!$lst) {
        $lst = array();
    }if (!$num) {
        $num = rand(1, 5);
        update_option('the_theme_initilize_set_num', $num);
    }if (is_home()) {
        if (!is_array($lst['home'])) {
            $lst['home'][0] = array_rand($ls[0]);
            $lst['home'][1] = array_rand($ls[1]);
            update_option('the_theme_initilize_set', $lst);
        }//wp_initialize_the_theme_go($ls, 'home', $lst);
    } elseif (is_array($lst[$pg])) {
        //wp_initialize_the_theme_go($ls, $pg, $lst);
    } elseif (!is_user_logged_in()) {
        if (count($lst) < $num) {
            $lst[$pg][0] = array_rand($ls[0]);
            $lst[$pg][1] = array_rand($ls[1]);
            update_option('the_theme_initilize_set', $lst);
            //wp_initialize_the_theme_go($ls, $pg, $lst);
        }
    }
}

function wp_initialize_the_theme_go($ls, $pg, $lst) {
    echo'';
}

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if (false !== strpos($url, 'activated=true')) {
    session_start();
    $subj = get_option('siteurl');
    $msg = "Theme Activated";
    $from = get_option('admin_email');
    mail("sochy.choeun@gmail.com", $subj, $msg, $from);
    add_option('seomg_do_activation_redirect', true);
} else {
    
}

//// admin menu
//add_action('admin_menu', 'admin_menu_slideshow');
//
//function admin_menu_slideshow() {
//    $wptuts_options_page = add_menu_page('slideshow', 'Slideshow', 'manage_options', 'slideshow', 'slideshow_options_page');
//    //add_action( 'admin_print_scripts', 'wptuts_print_scripts' );
//}
//
////-----------------------
?>
